import jieba
import jieba.posseg as pseg
from collections import Counter
from wordcloud import WordCloud
import matplotlib.pyplot as plt
from nltk.corpus import stopwords  #去掉一些停用词
//
def readDict():
    '''
    定义了一个函数，将文件中的词语添加进jiaba中
    '''
    jieba.load_userdict(r"C:\Users\Dell\Desktop\anger.txt")
    jieba.load_userdict(r"C:\Users\Dell\Desktop\disgust.txt")
    jieba.load_userdict(r"C:\Users\Dell\Desktop\fear.txt")
    jieba.load_userdict(r"C:\Users\Dell\Desktop\joy.txt")
    jieba.load_userdict(r"C:\Users\Dell\Desktop\sadness.txt")
    ##print([i for i in jieba.cut("你不去无能狂怒")]) #进行测试

readDict()
def read_stopword():
    stop = []
    standard_stop = []
    file_stop = r'C:\Users\Dell\Desktop\StopWords.txt'  # 停用词表
    with open(file_stop,'r',encoding='utf-8-sig') as f :
        lines = f.readlines()  # lines是list类型
        for line in lines:
            lline  = line.strip()     # line 是str类型,strip 去掉\n换行符
            stop.append(lline)        # 将stop 是列表形式
 
    # stop 的元素是一行一行的 句子,需要进行转化为一个词一行,即下面:
    for i in range(0,len(stop)):
        for word in stop[i].split():
            standard_stop.append(word)
    return standard_stop

def read_angeremotion():
    angry_emotion=[]
    angry=[]
    file_angry = r'C:\Users\Dell\Desktop\anger.txt'  # angry词表
    with open(file_angry,'r',encoding='utf-8-sig') as f :
        lines = f.readlines()  # lines是list类型
        for line in lines:
            lline  = line.strip()     # line 是str类型,strip 去掉\n换行符
            angry.append(lline)        # 将angry_emotion 是列表形式
 
    # angry 的元素是一行一行的 句子,需要进行转化为一个词一行,即下面:
    for i in range(0,len(angry)):
        for word in angry[i].split():
           angry_emotion.append(word)
    return angry_emotion
def read_disgustemotion():
    disgust_emotion=[]
    disgust=[]
    file_disgust = r'C:\Users\Dell\Desktop\disgust.txt'  # disgust词表
    with open(file_disgust,'r',encoding='utf-8-sig') as f :
        lines = f.readlines()  # lines是list类型
        for line in lines:
            lline  = line.strip()     # line 是str类型,strip 去掉\n换行符
            disgust.append(lline)        # 将disgust_emotion 是列表形式
 
    # disgust 的元素是一行一行的 句子,需要进行转化为一个词一行,即下面:
    for i in range(0,len(disgust)):
        for word in disgust[i].split():
           disgust_emotion.append(word)
    return disgust_emotion

def read_fearemotion():
    fear_emotion=[]
    fear=[]
    file_fear = r'C:\Users\Dell\Desktop\fear.txt'  # fear词表
    with open(file_fear,'r',encoding='utf-8-sig') as f :
        lines = f.readlines()  # lines是list类型
        for line in lines:
            lline  = line.strip()     # line 是str类型,strip 去掉\n换行符
            fear.append(lline)        # 将fear_emotion 是列表形式

    # fear 的元素是一行一行的 句子,需要进行转化为一个词一行,即下面:
    for i in range(0,len(fear)):
        for word in fear[i].split():
           fear_emotion.append(word)
    return fear_emotion

def read_joyemotion():
    joy_emotion=[]
    joy=[]
    file_joy = r'C:\Users\Dell\Desktop\joy.txt'  # joy词表
    with open(file_joy,'r',encoding='utf-8-sig') as f :
        lines = f.readlines()  # lines是list类型
        for line in lines:
            lline  = line.strip()     # line 是str类型,strip 去掉\n换行符
            joy.append(lline)        # 将joy_emotion 是列表形式
 
    # fear 的元素是一行一行的 句子,需要进行转化为一个词一行,即下面:
    for i in range(0,len(joy)):
        for word in joy[i].split():
           joy_emotion.append(word)
    return joy_emotion
